package com.kx.yooli.kx.wechat.mapper.nplm;

import com.kx.yooli.kx.wechat.entity.nplm.CustInfo;
import com.kx.yooli.kx.wechat.entity.nplm.NplmLoanContract;
import com.kx.yooli.kx.wechat.po.user.NplmBaseCustInfo;
import com.mybatisflex.annotation.UseDataSource;
import com.mybatisflex.core.BaseMapper;
import com.mybatisflex.core.query.QueryColumn;
import com.mybatisflex.core.query.QueryCondition;
import com.mybatisflex.core.query.QueryWrapper;
import jnr.ffi.Struct;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

public interface NplmLoanContractMapper extends BaseMapper<NplmLoanContract> {
    @UseDataSource("ds4")
    default List<NplmLoanContract> selectByCertNo(String idCard){
        return selectListByQuery(QueryWrapper.create()
                .select()
                .from(NplmLoanContract.class).where(NplmLoanContract::getCustNo).eq(idCard));
    }

    @UseDataSource("ds4")
    default List<String> selectLoanNoByCertNo(String idCard){
        return selectListByQueryAs(QueryWrapper.create()
                .select(NplmLoanContract::getLoanNo)
                .from(NplmLoanContract.class).where(NplmLoanContract::getCustNo).eq(idCard),String.class);
    }
    @UseDataSource("ds4")
    default List<String> selectLoanNoByIdCard(String idCard){
        return selectListByQueryAs(QueryWrapper.create().select(NplmLoanContract::getLoanNo).from(NplmLoanContract.class).leftJoin(CustInfo.class)
                .on(CustInfo::getCustNo,NplmLoanContract::getCustNo).where(CustInfo::getCertNo).eq(idCard).and(NplmLoanContract::getContractStatus).
                in('1','2','3'), String.class
        );
    }
      @UseDataSource("ds4")
    default List<Map> selectByIdCard(String idCard){
        return selectListByQueryAs(QueryWrapper.create().select(NplmLoanContract::getLoanNo).from(NplmLoanContract.class).leftJoin(CustInfo.class)
                .on(CustInfo::getCustNo,NplmLoanContract::getCustNo).where(CustInfo::getCertNo).eq(idCard).and("CONTRACT_STATUS in ('1','2','3')"), Map.class
              );
    }

    @UseDataSource("ds4")
    default List<Map> selectLoanNobyMobile(String mobile){
        return  selectListByQueryAs(QueryWrapper.create().select().from(NplmLoanContract.class).leftJoin(NplmBaseCustInfo.class)
                .on(NplmBaseCustInfo::getCustNo,NplmLoanContract::getCustNo)
                .leftJoin(CustInfo.class).on(CustInfo::getCustNo,NplmLoanContract::getCustNo)
                .where(NplmBaseCustInfo::getMobileTel).eq(mobile).and("CONTRACT_STATUS in ('1','2','3')"), Map.class
        );
    }


    @UseDataSource("dh")
    default NplmLoanContract selectLoanNoObjectByCertNo(String id){
        return selectOneWithRelationsByQuery(QueryWrapper.create()
                .select()
                .from(NplmLoanContract.class).where(NplmLoanContract::getLoanNo).eq(id).limit(1));
    }

}
